package cn.hist.hfp.converter;

import cn.hist.hfp.entity.User;
import cn.hist.hfp.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserConverter {

    private final
    PetOrderConverter petOrderConverter;

    private final
    CommodityOrderConverter commodityOrderConverter;

    private final ReservationConverter reservationConverter;

    @Autowired
    public UserConverter(PetOrderConverter petOrderConverter, CommodityOrderConverter commodityOrderConverter, ReservationConverter reservationConverter) {
        this.petOrderConverter = petOrderConverter;
        this.commodityOrderConverter = commodityOrderConverter;
        this.reservationConverter = reservationConverter;
    }

    public UserVO convert(User user) {
        return UserVO.builder().name(user.getName()).id(user.getId())
                .petOrders(petOrderConverter.convert(user.getPetOrders()))
                .commodityOrders(commodityOrderConverter.convert(user.getCommodityOrders()))
                .reservation(reservationConverter.convert(user.getReservations()))
                .build();
    }
}
